﻿#include"unrealircd.h"
/**
 * 构造各种http响应数据
 */




/**
 * 进行200响应，代表请求成功
 */
int web_http_response_200(WebUser *user){
	ResponseData *data=user->responseData;
	data->responseStatus=200;
	safe_strdup(data->responseReason,"OK");


	web_http_response_header_complied(user);
	user->requestStatus=REQUESTSTATUS_RESPONSE_TRANSFER;
	return 0;
}

/**
 * 进行400响应，代表客户端请求的语法错误，服务器无法理解
 */
int web_http_response_400(WebUser *user){
	ResponseData *data=user->responseData;
	data->responseStatus=400;
	safe_strdup(data->responseReason,"Bad Request");
	safe_strdup(data->responseBody,"Bad Request");
	data->responseBodyLength=strlen(data->responseBody);



	web_http_response_header_complied(user);
	user->requestStatus=REQUESTSTATUS_RESPONSE_TRANSFER;
	return 0;
}

/**
 * 进行404响应，代表服务器无法根据客户端的请求找到资源（网页）
 */
int web_http_response_404(WebUser *user){
	ResponseData *data=user->responseData;
	data->responseStatus=404;
	safe_strdup(data->responseReason,"Not Found");
	safe_strdup(data->responseBody,"Not Found");
	data->responseBodyLength=strlen(data->responseBody);



	web_http_response_header_complied(user);
	user->requestStatus=REQUESTSTATUS_RESPONSE_TRANSFER;
	return 0;
}

/**
 * 进行500响应，代表服务器错误，无法完成任务
 */
int web_http_response_500(WebUser *user){
	ResponseData *data=user->responseData;
	data->responseStatus=500;
	safe_strdup(data->responseReason,"Internal Server Error");
	safe_strdup(data->responseBody,"Internal Server Error");
	data->responseBodyLength=strlen(data->responseBody);



	web_http_response_header_complied(user);
	user->requestStatus=REQUESTSTATUS_RESPONSE_TRANSFER;
	return 0;
}




/**
 * response响应的头部增加一些固定的头部
 */
void web_http_response_header_complied(WebUser *user){
	responseData_add_header(user->responseData,"Content-Length",strdup(int_to_string(user->responseData->responseBodyLength)));
	responseData_add_header(user->responseData,"Proxy-Connection","close");


	//responseData_add_header(user->responseData,strdup(),strdup());
}